#include <cstdio>
#include <algorithm>
using namespace std;
const int N=30040;
int p[N];
int find(int x){
    return p[x]==x ? x : p[x]=find(p[x]);
}
void join(int a,int b){
    int fa=find(a);
    int fb=find(b);
    if(fa!=fb){
        p[fb]=fa;
    }
}
int main(void){
    int n,m;
    while(~scanf("%d%d",&n,&m)){
        if(n==0 && m==0){
            break;
        }
        for(int i=0;i<n;i++){
            p[i]=i;
        }
        int a,b,f;
        while(m--){
            scanf("%d",&a);
            if(a>0){
                scanf("%d",&f);
                a-=1;
                while(a--){
                    scanf("%d",&b);
                    join(f,b);
                }
            }
        }
        int ans=0;
        for(int i=0;i<n;i++){
            if(find(i)==p[0]){
                ans++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}
